<!--
 * @Descripttion: 核酸宝项目前端
 * @version: 
 * @Author: 杜宇轩
 * @Date: 2022-05-22 05:27:34
 * @LastEditors: 杜宇轩
 * @LastEditTime: 2022-05-22 06:20:43
-->
<template>
  <div class="AdNAT_box">
    <div class="AdNAT_box_header">
      <i class="el-icon-menu"/>
      检测结果记录
    </div>
    <el-button
      class="AdNAT_addButton"
      size="small"
      type="success"
      @click="dialogFormVisible = true"
    >
      <i class="el-icon-plus"/>
      上传检测结果
    </el-button>
    <el-table
      class="AdNAT_table"
      :data="tableData"
      min-height="500px"
      :default-sort = "{prop: 'reagentBottleId', order: 'ascending'}"
      highlight-current-row
      border
      stripe
    >
      <el-table-column
        prop="reagentBottleId"
        label="试剂瓶编号"
        width="180"
      />
      <el-table-column
        prop="institution"
        label="检测机构"
        min-width="270"
      />
      <el-table-column
        prop="showSamplingTime"
        label="检测时间"
        width="270"
      />
      <el-table-column
        prop="result"
        label="检测结果"
        width="180"
      />
    </el-table>
    <el-dialog
      title="上传检测结果"
      width="600px"
      :visible.sync="dialogFormVisible"
      :append-to-body="true"
    >
      <el-form label-width="120px">
        <el-form-item label="试剂瓶编号">
          <el-input
            style="width: 240px;"
            v-model="addForm.reagentBottleId"
            placeholder="请输入试剂瓶编号"
          />
        </el-form-item>
        <el-form-item label="检测机构">
          <el-input
            style="width: 240px;"
            v-model="addForm.institution"
            placeholder="请输入检测机构"
          />
        </el-form-item>
        <el-form-item label="检测时间">
          <el-date-picker
            style="width: 240px;"
            v-model="addForm.showSamplingTime"
            type="datetime"
            placeholder="请选择检测时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <el-form-item label="检测结果">
          <el-select
            style="width: 240px;"
            v-model="addForm.result"
            placeholder="请选择检测结果"
          >
            <el-option label="阴性" value="阴性"/>
            <el-option label="阳性" value="阳性"/>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  doctorCheckResult,
  doctorAddOneResult
} from '@/api/doctor/doctorResult';
export default {
  data() {
    return {
      addForm: {
        reagentBottleId: '',
        samplingTime: '',
        showSamplingTime: '',
        institution: '',
        result: ''
      },
      tableData: [],
      dialogFormVisible: false
    }
  },
  created() {
    doctorCheckResult().then((data) => {
      data.forEach((item) => {
        let str = item.samplingTime.substr(0, 19);
        str = str.replaceAll('T', ' ');
        item.showSamplingTime = str;
      });
      this.tableData = data;
    });
  },
  methods: {
    handleSubmit() {
      let str = this.addForm.showSamplingTime;
      str = str.replaceAll(' ', 'T');
      str = str + ".000";
      this.addForm.samplingTime = str;
      const obj = {};
      obj.reagentBottleId = this.addForm.reagentBottleId;
      obj.samplingTime = this.addForm.samplingTime;
      obj.showSamplingTime = this.addForm.showSamplingTime;
      obj.institution = this.addForm.institution;
      obj.result = this.addForm.result;
      doctorAddOneResult(obj).then(() => {
        this.$message.success('上传成功');
        this.dialogFormVisible = false;
        this.tableData.unshift(obj);
      });
    }
  }
}
</script>

<style lang="scss">
.AdNAT_box {
  background: #FFFFFF;
  display: inline-block;
  width: calc(100% - 100px);
  min-width: 1000px;
  margin: 50px 50px 0px 50px;
  border-radius: 5px;
  box-shadow: 1px 1px 3px 3px rgba(0,0,0,0.2);

  .AdNAT_box_header {
    background: #EEE;
    padding: 5px;
    border-radius: 5px 5px 0px 0px;
    border-bottom: 1px solid #DDD;
  }

  .AdNAT_addButton {
    margin: 10px 20px 10px 10px;
    float: right;
    font-size: 14px;
  }

  .AdNAT_table {
    width: calc(100% - 40px);
    margin: 20px 20px 10px 20px;

    .AdNAT_table_expand {
      font-size: 0;
    }
    .AdNAT_table_expand label {
      width: 90px;
      color: #005187;
    }
    .AdNAT_table_expand .el-form-item {
      margin: 0px 0px 0px 10px;
      width: 60%;
    }
  }
}

</style>